package beans;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import bdd.DBLink;

/**
 *
 * @author sojousse
 */
public class ListeEtudiantEns {
    private DBLink dblink;
     List<Etudiant> listeEtudiantEns;

     public ListeEtudiantEns()
     {
         dblink = new DBLink();
         listeEtudiantEns = new ArrayList<Etudiant>();
     }

     public ListeEtudiantEns(List<Etudiant> listeEtudiantEns)
     {
         dblink = new DBLink();
         this.listeEtudiantEns = listeEtudiantEns;
     }

    public List<Etudiant> getListeEtudiantEns()
    {
        return this.listeEtudiantEns;
    }

    public void setListeEtudiantEns(List<Etudiant> listeEtudiantEns)
    {
        this.listeEtudiantEns=listeEtudiantEns;
    }

    public void add(Etudiant etudiant)
    {
        this.listeEtudiantEns.add(etudiant);
    }

    public void recupererListeEtudiantEns(int promotion){
      try
      {
            DBLink db = new DBLink();
            db.connexion();
            String rq = "select numEtudiant "
                    + "from JNTETUDIANTPROMOTION "
                    + "where numpromotion = " + promotion
                    + "  order by numEtudiant";

            PreparedStatement pst = db.getConnection().prepareStatement(rq);
            System.out.println(rq);
            Etudiant e = new Etudiant();
            db.setPst(pst);
            ResultSet rs = db.getPst().executeQuery();
            db.setRs(rs);

            while(db.getRs().next())
            {
                e=new Etudiant();
                e.setNumEtudiant(db.getRs().getInt("numEtudiant"));
                this.listeEtudiantEns.add(e);
            }
            db.getConnection().close();
      }
      catch (SQLException ex)
      {
            Logger.getLogger(ListeECEns.class.getName()).log(Level.SEVERE, null, ex);
      }
  }

}
